<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<sec:authentication property="principal" var="currentPrincipal" scope="page"/>

<div class="modal-dialog ms-modal-dialog">
  <div class="modal-content">

    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
        class="sr-only">Close</span></button>
      <h4 class="modal-title">修改基本信息</h4>
    </div>

    <form class="form-horizontal ms-form form-personal-info" method="POST"
          action="${ctx.host}/agents/${agentCompany.id}" data-validate="true">

      <input type="hidden" name="_method" value="PATCH"/>
      <input type="hidden" name="agentCompanyId" value="${agentCompany.id}"/>

      <div class="modal-body">
        <div class="form-group  ms-form-group">
          <label class="control-label col-xs-3"><span class="text-red">*</span>代理名称：</label>
          <div class="col-xs-8">
            <input type="text" class="form-control name" name="name" value="${agentCompany.name}"
                   data-validate="required" tabindex="5" placeholder="中文名称" autocomplete="off"/>
            <span class="text-red check"></span>
          </div>
        </div>

        <div class="form-group  ms-form-group">
          <label class="control-label col-xs-3"><span class="text-red">*</span>Email：</label>
          <div class="col-xs-8">
            <input type="text" class="form-control" name="contactEmail" value="${agentCompany.contactEmail}"
                   data-validate="required" tabindex="5" placeholder="中文名称" autocomplete="off"/>
          </div>
        </div>

        <div class="form-group  ms-form-group">
          <label class="control-label col-xs-3"><span class="text-red">*</span>返点率(%)：</label>
          <div class="col-xs-8">
            <input ${not empty agentCompany.primaryAgent ? 'readonly': ''} type="text" class="form-control" name="rate" value="${agentCompany.rate}" data-validate="number"
                   tabindex="5" placeholder="中文名称" autocomplete="off"/>
          </div>
        </div>

        <c:if test="${not empty agentCompany.primaryAgent}">
          <div class="form-group  ms-form-group">
            <label class="control-label col-xs-3"><span class="text-red">*</span>提成率(%)：</label>
            <div class="col-xs-8">
              <input type="text" class="form-control" name="primaryAgentRate" value="${agentCompany.primaryAgentRate}" data-validate="number"
                     tabindex="5" placeholder="一级代理提成率" autocomplete="off"/>
            </div>
          </div>
        </c:if>

        <c:if test="${!agentCompany.type.company}">
          <div class="form-group ms-form-group">
            <label class="col-xs-3 control-label"><span class="text-red">*</span>代理类型：</label>
            <div class="col-xs-8">
              <select name="type" id="agentType" class="select2  form-control" data-validate="required" tabindex="3">
                <option></option>
                <c:forEach var="agentType" items="${enums['AgentType']}">
                  <option value="${agentType}" ${agentCompany.type eq agentType ? 'selected' : ''}>${agentType.description}</option>
                </c:forEach>
              </select>
            </div>
          </div>
        </c:if>

        <div class="modal-footer ms-modal-footer">
          <button type="submit" class="btn ms-btn btn-primary">确定</button>
          <button type="button" class="btn ms-btn ms-btn-gary" data-dismiss="modal">取消</button>
        </div>
    </form>
  </div>
</div>
<script type="text/javascript">
  $(document).ready(function () {
    $('select[name="type"]').select2({
      theme: "classic",
      placeholder: '请选择代理类型',
      minimumResultsForSearch: -1,
      allowClear: true
    });

    $('input[name="primaryAgentRate"]').on("change", function () {
      debugger
      var primaryAgentRate = parseInt($(this).val())%10;
      $(this).val(primaryAgentRate)
    })
  })
</script>